All Questions
12 questions
3votes
1answer
70views
Scala: Cumulative String Tokenisation
I'm trying to split an incoming stream of strings into cumulative tokens per line item using a function below, ...
1vote
2answers
334views
Count Substrings for a binary string
Problem is taken from leet code. Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings ...
2votes
0answers
319views
KMP algorithm in scala
I implemented KMP pattern matching algorithm in Scala. My code works but it looks more imperative and a scala translation of C/C++ implementation. I am not able to figure out how to manage multiple ...
1vote
1answer
121views
Find first repeating Char in String
Given a string, find the first repeating character in it. Examples: firstUnique("Vikrant") → None ...
0votes
1answer
531views
Print words in decreasing order of frequency in Scala
Given a string print its words in decreasing order of frequency. Example: i/p - "aa bbb ccc aa ddd aa ccc" o/p - aa,ccc,ddd,bbb Scala: ...
0votes
1answer
385views
find if one string is a valid anagram of another , in scala
Question is taken from leet code. Problem Given two strings s and t , write a function to determine if t is an anagram of s. Examples ...
4votes
1answer
929views
Longest Substring Without Repeating Characters in Scala
Question is taken from Leetcode and solution works for their test cases. I do see a scope of improvement and make it more functional (getting rid of vars and mutables data structures). Please suggest ...
1vote
1answer
497views
Check Is Anagram Scala HashMap based implementation
Here is the HashMap based implementation of the function checking whether two strings are anagrams: Example: ...
4votes
3answers
137views
Compare ZIP codes, disregarding leading zeros
I have a function that compares ZIP codes. It also has to handle cases where the input ZIP code be missing leading zeros, have extraneous leading zeros. This is what I've come up with. I don't have ...
1vote
2answers
233views
Find the most frequent character in a string
I'm trying to solve this problem https://community.topcoder.com/stat?c=problem_statement&pm=40 Given a string made up of ONLY letters and digits, determine which character is repeated the ...
7votes
3answers
6kviews
Checking for balanced parentheses
I wrote a method to check if each parenthesis in a string is closed. It should take into account the order in which a parenthesis is presented, e.g. "hello)goodbye(" should return false even though ...
6votes
3answers
3kviews
A safer way to cut a string
I want to get just the first line of a big string. Currently, here's how I do it: ...